// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import App from './App.vue';
import router from './router';
import Navigation from 'vue-navigation';
import {getStore, getUser, isWeiXin, timeStamp, timeMsec} from './assets/js/tools';
import {ipconfig} from './assets/js/ipconfig';


// import $ from 'zepto';

//按需引入mint-ui组件
import { Indicator, MessageBox, Toast, Swipe, SwipeItem, Actionsheet, Loadmore } from 'mint-ui';
window.Indicator = Indicator;
window.MessageBox= MessageBox;
window.Toast = Toast;
Vue.component(Swipe.name, Swipe);
Vue.component(SwipeItem.name, SwipeItem);
Vue.component(Actionsheet.name, Actionsheet);
Vue.component(Loadmore.name, Loadmore);

//引入日期选择组件
import Calendar from 'vue2-datepick';
Vue.use(Calendar);

//引入weui
import '../node_modules/weui/dist/style/weui.css';

//引入common.css
import './assets/css/common.css';

//引入moment
import Moment from 'moment';
Moment.locale('zh-cn');

//引入v-distpicker地区选择
import VDistpicker from 'v-distpicker'
Vue.component('v-distpicker', VDistpicker);

//引入图片剪裁vue-croppa
import Croppa from 'vue-croppa';
import 'vue-croppa/dist/vue-croppa.css';
Vue.use(Croppa);

//滚动条
import VueScroll from 'vuescroll';
Vue.use(VueScroll);

//引入进度条组件
import VueProgressBar from 'vue-progressbar';
Vue.use(VueProgressBar, {
  color: '#874545',
  thickness: '10px',
  transition: {
    speed: '0.3s',
    opacity: '0.6s',
    termination: 300
  },
  autoRevert: true,
  position:'relative',
  inverse: false
});

//流媒体播放器
import VueVideoPlayer from 'vue-video-player';
import 'video.js/dist/video-js.css';
Vue.use(VueVideoPlayer);


//过滤器
Vue.filter('convertDate',function (value) {
  //2018-05-24 14:46:36
  if(!value){
    return value;
  }
  let time = timeMsec(value);
  return Moment(time).format('MM-DD HH:mm');
});
Vue.filter('convertDate2',function (value) {
  if(!value){
    return value;
  }
  let time = timeMsec(value);
  return Moment(time).format('MM-DD HH:mm:ss');
});
Vue.filter('year',function (value) {
  //2018-05-24 14:46:36
  if(!value){
    return value;
  }
  let time = timeMsec(value);
  return Moment(time).format('YYYY年');
});
Vue.filter('toDecimal',function (value) {
  if(!isNaN(value)){
    return value.toFixed(2);
  }
});
//分割视频时间
Vue.filter('timeStamp',function (value) {
  return timeStamp(value);
});


//全局组件
import FooterVue from './components/common/footerVue/footerVue.vue';
import BlockTitle from './components/common/blockTitle/blockTitle.vue';
import SpecialList from './components/common/specialList/specialList.vue';
import ProductList from './components/common/productList/productList.vue';
import Pagination from './components/common/pagination/pagination.vue';
import CountDown from './components/common/countDown/countDown.vue';
import CountTime from './components/common/countTime/countTime.vue';
import Choice from './components/common/choice/choice.vue';
import CollectionFooter from './components/common/collectionFooter/collectionFooter.vue';

//声明全局组件
Vue.component('footerVue',FooterVue);
Vue.component('blockTitle',BlockTitle);
Vue.component('specialList',SpecialList);
Vue.component('productList',ProductList);
Vue.component('pagination',Pagination);
Vue.component('countDown',CountDown);
Vue.component('countTime',CountTime);
Vue.component('choice',Choice);
Vue.component('collectionFooter',CollectionFooter);


router.beforeEach((to, from, next) => {
  // 判断是否需要登录权限
  if (to.matched.some(res => res.meta.requireLogin)) {
    // 判断是否登录
    if (getUser()) {
      next();
    }else {
      if(isWeiXin()){
        let toUrl = ipconfig.wxWebAuthUrl+'#/login?redirect='+encodeURIComponent(to.fullPath);
        toUrl = encodeURIComponent(toUrl);
        let weUrl = getStore('weUrl');
        weUrl = weUrl.replace('-URL-',toUrl);
        window.location.href = weUrl;
      }else {
        next({
          path: "/login",
          query: {redirect: to.fullPath}
        });
      }
    }
  }else {
    next();
  }

});



Vue.config.productionTip = false;

Vue.use(Navigation, {router});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
});
